package com.panfeng.xcloud.boss.provider.member.web.controller;

import com.panfeng.xcloud.boss.provider.member.service.IUploadService;
import com.panfeng.xcloud.common.core.web.vo.ResponseVO;
import com.panfeng.xcloud.common.security.annotation.NotNeedAccess;
import com.panfeng.xcloud.common.security.web.support.BaseController;
import com.panfeng.xcloud.component.oss.model.UploadResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 图片上传服务模块
 *
 * @author xiaobo
 * @version 1.0
 * @since 2019-08-08
 */
//@ApiIgnore
@RestController
@RequestMapping("user/upload")
@Api(tags = {"图片上传服务模块"})
@Slf4j
public class UserUploadController extends BaseController {

    @Autowired
    private IUploadService iUploadService;

    /**
     * 图片上传
     *
     * @param multipartFile
     * @return
     */
    @NotNeedAccess
    @RequestMapping(value = "/imgUpload", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "图片上传(肖博)", httpMethod = "POST", notes = "图片上传(肖博)")
    public ResponseVO imgUpload(@RequestParam("imageFile") MultipartFile multipartFile) {
        UploadResult uploadResult = iUploadService.imgUpload(multipartFile);
        return null != uploadResult && uploadResult.getResult() ?
                ResponseVO.with(uploadResult.getUrl()) : ResponseVO.error();
    }

}
